home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v7n19.arc / NUMLIST.C < prev    next >
C/C++ Source or Header  |  1988-10-14  |  1KB  |  42 lines

  1. /* numlist.c
  2.     List programs with line numbers.  For MSC 4.0/5.0 and TC 1.0 
  3.         To compile for MSC:  cl numlist.c
  4.         To compile for TC:   tcc numlist
  5.  */
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. FILE *infil;                   /* FILE TO BE CHECKED */
  10. char linebuf[BUFSIZ];          /* LINE BUFFER FOR READING FROM FILE */
  11.  
  12. main(argc,argv)
  13. char *argv[];
  14. int argc;
  15. {
  16.     int line_cnt;
  17.  
  18.         /* Check arguments for filename or '?' (help) flag */
  19.     if((argc < 2) || strchr(argv[1],'?'))
  20.     {
  21.         fputs("\007Usage:",stderr);
  22.         fputs("  numlist [d:path\\]inputfile\n",stderr);
  23.         fputs("                or  numlist \
  24.             [d:path\\]inputfile > [d:path\\]outputfile",stderr);
  25.         exit(1);
  26.     }
  27.  
  28.     if(!(infil = fopen(argv[1],"r")))   /* open input file */
  29.     {
  30.         fprintf(stderr,"\007CAN'T OPEN INPUT FILE: %s!",argv[1]);
  31.         exit(1);
  32.     }
  33.  
  34.         /* get each line and print it preceded by the line number */
  35.     for( line_cnt = 1; fgets(linebuf,BUFSIZ,infil); line_cnt++)
  36.         printf ("%3d %s",line_cnt, linebuf);
  37.     
  38.     fclose(infil);                        /* open the file */
  39.     exit(0);
  40. }
  41.  
  42.